from rest_framework import serializers
from .models import Merchant, MerchantAddress, MerchantGrade, Category, Goods, Coupon


class MerchantSer(serializers.ModelSerializer):

    class Meta:
        model = Merchant
        fields = '__all__'


class MerchantAddressSer(serializers.ModelSerializer):

    merchant_is = serializers.SerializerMethodField(read_only=True)

    def get_merchant_is(self, obj):
        return obj.merchant.title

    class Meta:
        model = MerchantAddress
        fields = '__all__'


class MerchantGradeSer(serializers.ModelSerializer):
    merchant_is = serializers.SerializerMethodField(read_only=True)

    def get_merchant_is(self, obj):
        return obj.merchant.title

    class Meta:
        model = MerchantGrade
        fields = '__all__'


class CateSer(serializers.ModelSerializer):
    merchant_is = serializers.SerializerMethodField(read_only=True)

    def get_merchant_is(self, obj):
        return obj.merchant.title

    class Meta:
        model = Category
        fields = '__all__'


class GoodsSer(serializers.ModelSerializer):
    merchant_is = serializers.SerializerMethodField(read_only=True)
    cate_is = serializers.SerializerMethodField(read_only=True)

    def get_merchant_is(self, obj):
        return obj.merchant.title

    def get_cate_is(self, obj):
        return obj.merchant_cate.name

    class Meta:
        model = Goods
        fields = '__all__'


class CouponSer(serializers.ModelSerializer):
    merchant_is = serializers.SerializerMethodField(read_only=True)

    def get_merchant_is(self, obj):
        return obj.merchant.title

    class Meta:
        model = Coupon
        fields = '__all__'
